package com.antexpress.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 *
 * @author Andy
 */
public class DataUtil {
    
    public static String formatSalary(double salary) {
        DecimalFormat df = new DecimalFormat("#,###.00");
        String xs = df.format(salary);
        return xs;
    }
    
    public static String getHtmlDate(Date date) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        return df.format(date);
    }
    
    //生成32位唯一序列（UUID）
    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }
    
    //生成随机6位字符
    public static String getRandomCode() {
        return getUUID().substring(0, 6).toUpperCase();
    }
    
    //生成当前时间的时间戳
    public static Timestamp getTimestamp() {
        return new Timestamp(new Date().getTime());
    }
    
    public static String dealProvinceName(String name){
        if(name.substring(name.length()-1).equals("省")){
            return name.replace("省", "");
        }else if(name.substring(name.length()-1).equals("市")){
            return name.replace("市", "");
        }else if(name.substring(name.length()-3).equals("自治区")){
            return name.replace("自治区", "");
        }
        return name;
    }
    
    public static String dealCityName(String name){
        if(name.substring(name.length()-1).equals("市")){
            return name.replace("市", "");
        }else if(name.substring(name.length()-2).equals("地区")){
            return name.replace("地区", "");
        }else if(name.equals("市辖区")){
            return "Urban";
        }else if(name.substring(name.length()-2).equals("治州")){
            return name.replace("自治州", "");
        }
        return name;
    }
    
    public static String dealDistrictName(String name){
        if(name.substring(name.length()-1).equals("县")){
            return name.replace("县", "");
        }if(name.substring(name.length()-1).equals("区")){
            return name.replace("区", "");
        }if(name.substring(name.length()-1).equals("市")){
            return name.replace("市", "");
        }
        return name;
    }
    
    public static String dealTownName(String name){
        if(name.substring(name.length()-1).equals("镇")){
            return name.replace("镇", "");
        }if(name.substring(name.length()-1).equals("乡")){
            return name.replace("乡", "");
        }else if(name.substring(name.length()-2).equals("发区")){
            name = name.replace("技术开发区", "");
            name = name.replace("开发区", "");
            return name;
        }if(name.substring(name.length()-2).equals("事处")){
            name = name.replace("街道办事处", "");
            name = name.replace("地区办事处", "");
            return name;
        }
        return name;
    }
}
